package com.hgy.carsb.controller;


import com.hgy.carsb.entity.EveryMonthData;
import com.hgy.carsb.entity.Total;
import com.hgy.carsb.service.InfoService;
import com.hgy.carsb.service.TotalTrendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/total")
public class TotalTrendController {

    @Autowired
    private TotalTrendService totalTrendService;

    private int year = 2020;

    @PostMapping("/trend")
    @ResponseBody
    public List<EveryMonthData> getTrend(@RequestParam("index")String command){
        List<EveryMonthData> list = new ArrayList<>();
        String code1 = "";
        String code2 = "";
        switch (command){
            case "0":
                code1 = "interest";
                code2 = "income";
                break;
            case "1":
                code1 = "dept";
                code2 = "asset";
                break;
            case "2":
                code1 = "asset";
                code2 = "income";
                break;
        }
        list.add(totalTrendService.getSum(year, code1, code2, "FAW"));
        list.add(totalTrendService.getMonth(year, code1, code2, "FAW"));
        list.add(totalTrendService.getYear(year, code1, code2, "FAW"));
        return list;
    }
}
